package com.future.heatwave

import android.app.Application
import com.google.android.gms.ads.identifier.AdvertisingIdClient
import java.util.UUID
import kotlin.jvm.internal.Intrinsics


class App: Application() {

    override fun onCreate() {
        super.onCreate()
        instance = this
    }

    fun getAppInfo(timestamp:String):String{

        val packageInfo = packageManager.getPackageInfo(packageName, 0)
        val versionName = packageInfo.versionName
        val appPackageName = packageInfo.packageName
        val str = versionName+appPackageName+ System.currentTimeMillis()
        Intrinsics.checkNotNullExpressionValue(str, "builder.toString()")
        val bytes: ByteArray = str.toByteArray(Charsets.UTF_8)
        Intrinsics.checkNotNullExpressionValue(bytes, "this as java.lang.String).getBytes(charset)")
        val uuid = UUID.nameUUIDFromBytes(bytes).toString()

        val appInfo = "$uuid&$appPackageName&V$versionName"
//        Log.e("bLog", "appInfo *********  ${appInfo}")
        return appInfo
    }

    fun getAuthorization(timestamp:String): String {

        val currentTimeMillis = System.currentTimeMillis()
        val stringBuffer: String = StringBuffer().append(packageName).append(10000)
            .append(timestamp).toString()
        val auth = EncryptUtils.encryptMD5ToString(stringBuffer)
//        Log.e("bLog", "Authorization *********  ${auth}")
        return auth
    }


    companion object {
        private lateinit var instance: App

        fun getInstance(): App {
            return instance
        }
    }

}